import { get, post } from "@/utils/request";

export async function clone(id: number) {
  const res = await post("/operate/clone", { id });
  return res.json();
}

export async function pull(id: number) {
  const res = await post("/operate/pull", { id });
  return res.json();
}

export async function install(id: number) {
  const res = await post("/operate/install", { id });
  return res.json();
}

export async function build(
  id: number | string,
  git_commit_id: number | string,
  build_time: string,
  snapshot_description: string
) {
  const res = await post("/operate/build", {
    id,
    git_commit_id,
    build_time,
    snapshot_description,
  });
  return res.json();
}

export async function deploy(
  id: number | string,
  snapshot_id: number,
  deploy_time: string
) {
  const res = await post("/operate/deploy", { id, snapshot_id, deploy_time });
  return res.json();
}

export async function rewind(id: number | string, snapshot_id: number) {
  const res = await post("/operate/rewind", { id, snapshot_id });
  return res.json();
}

export async function gitlog(
  id: number | string,
  page_index: number = 1,
  page_size: number = 10
) {
  const res = await get("/operate/gitlog", { id, page_index, page_size });
  return res.json();
}
